﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Linq;
using System.Web;
using System.Web.Security;
using LIMIS.Models;
using WebMatrix.WebData;

namespace LIMIS.Common
{
    public static class LIMISDbInit
    {
        public static void startInit()
        {
            //using (var context = new LIMISDbContext())
            //{
            //    if (!context.Database.Exists())
            //    {
            //         Create the SimpleMembership database without Entity Framework migration schema
            //        ((IObjectContextAdapter)context).ObjectContext.CreateDatabase();
            //        LIMISDbContext db = new LIMISDbContext();
            //        db.Database.Initialize(true);
            //    }
            //}
            WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true);
            if (!Roles.RoleExists("超级管理员"))
                Roles.CreateRole("超级管理员");

            if (!WebSecurity.UserExists("admin"))
                WebSecurity.CreateUserAndAccount("admin", "adminlimis");

            if (!Roles.GetRolesForUser("admin").Contains("超级管理员"))
                Roles.AddUsersToRole(new[] { "admin" }, "超级管理员");
        }
    }
}